package hbm;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

/**
 * A data access object (DAO) providing persistence and search support for
 * Habitacion entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see hbm.Habitacion
 * @author MyEclipse Persistence Tools
 */

public class HabitacionDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(HabitacionDAO.class);
	// property constants
	public static final String TIPO_HABITACION_ID_TIPO_HABITACION = "tipoHabitacionIdTipoHabitacion";
	public static final String HOTEL_ID_HOTEL = "hotelIdHotel";
	public static final String CUENTA_ID_CUENTA = "cuentaIdCuenta";
	public static final String NUMERO_HABITACION = "numeroHabitacion";
	public static final String ESTADO = "estado";

	public void save(Habitacion transientInstance) {
		log.debug("saving Habitacion instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Habitacion persistentInstance) {
		log.debug("deleting Habitacion instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Habitacion findById(java.lang.Integer id) {
		log.debug("getting Habitacion instance with id: " + id);
		try {
			Habitacion instance = (Habitacion) getSession().get(
					"hbm.Habitacion", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Habitacion instance) {
		log.debug("finding Habitacion instance by example");
		try {
			List results = getSession().createCriteria("hbm.Habitacion").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Habitacion instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Habitacion as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByTipoHabitacionIdTipoHabitacion(
			Object tipoHabitacionIdTipoHabitacion) {
		return findByProperty(TIPO_HABITACION_ID_TIPO_HABITACION,
				tipoHabitacionIdTipoHabitacion);
	}

	public List findByHotelIdHotel(Object hotelIdHotel) {
		return findByProperty(HOTEL_ID_HOTEL, hotelIdHotel);
	}

	public List findByCuentaIdCuenta(Object cuentaIdCuenta) {
		return findByProperty(CUENTA_ID_CUENTA, cuentaIdCuenta);
	}

	public List findByNumeroHabitacion(Object numeroHabitacion) {
		return findByProperty(NUMERO_HABITACION, numeroHabitacion);
	}

	public List findByEstado(Object estado) {
		return findByProperty(ESTADO, estado);
	}

	public List findAll() {
		log.debug("finding all Habitacion instances");
		try {
			String queryString = "from Habitacion";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Habitacion merge(Habitacion detachedInstance) {
		log.debug("merging Habitacion instance");
		try {
			Habitacion result = (Habitacion) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Habitacion instance) {
		log.debug("attaching dirty Habitacion instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Habitacion instance) {
		log.debug("attaching clean Habitacion instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}